package macrochip.vison.com.gps.manager;

import com.vison.baselibrary.listeners.AnalysisListener;
import com.vison.baselibrary.utils.ObjectUtils;

import macrochip.vison.com.gps.mode.SwitchType;

/**
 * Created by XiaoShu on 2017/11/3 0003.
 */

public class DataUtils {
    private static boolean isNewMode;
    private DataUtils(){

    }

    private static class SingleHolder{
        private static DataUtils instance = new DataUtils();
    }

    public static DataUtils getInstance(){
        return DataUtils.SingleHolder.instance;
    }
    /**
     * 数据解析
     */
    public static void visonGps(AnalysisListener analysisListener, byte[] data) {
        if (null == analysisListener) {
            return;
        }
        byte[] newData = new byte[data.length - 4 - 1];
        System.arraycopy(data, 4, newData, 0, newData.length);
        switch (ObjectUtils.bytesToHexString(new byte[] {data[3]})) {
            case "00":  // 电量
                analysisListener.data(SwitchType.NOTIFY_TYPE_UPDATE_FLY_INFO_PLANE_V, new byte[]{data[4],data[5]});
                analysisListener.data(SwitchType.NOTIFY_TYPE_UPDATE_FLY_INFO_CONTROL_V, new byte[]{data[6],data[7]});
                analysisListener.data(SwitchType.NOTIFY_TYPE_UPDATE_FLY_INFO_LOCATION, new byte[]{data[8],data[9],data[10],data[11],data[12],data[13],data[14],data[15]});
                analysisListener.data(SwitchType.NOTIFY_TYPE_UPDATE_FLY_INFO_GPS,new byte[]{data[16]});
                analysisListener.data(SwitchType.NOTIFY_TYPE_UPDATE_FLY_INFO_HEAD_ANGLE,new byte[]{data[17],data[18]});
                analysisListener.data(SwitchType.NOTIFY_TYPE_UPDATE_FLY_INFO_LEVEL_DISTANCE, new byte[]{data[19],data[20]});
                analysisListener.data(SwitchType.NOTIFY_TYPE_UPDATE_FLY_INFO_VERTICAL_DISTANCE, new byte[]{data[21],data[22]});
                analysisListener.data(SwitchType.NOTIFY_TYPE_UPDATE_FLY_INFO_LEVEL_SPEED,new byte[]{data[23],data[24]});
                analysisListener.data(SwitchType.NOTIFY_TYPE_UPDATE_FLY_INFO_VERTICAL_SPEED,new byte[]{data[25],data[26]});
                break;

            case "02":  // 提示信息
                analysisListener.data(SwitchType.NOTIFY_TYPE_UPDATE_FLY_SEARCH_STAUS , new byte[]{data[4],data[5]});
                break;

            case "01":
                analysisListener.data(SwitchType.NOTIFY_TYPE_UPDATE_FLY_SEARCH_PHOTO, new byte[]{data[4]});
                break;

            case "03":
                analysisListener.data(SwitchType.NOTIFY_SETTING_DATA,new byte[]{data[4],data[5],data[6],data[7]});
                break;

            case "06":
                analysisListener.data(SwitchType.NOTIFY_TYPE_UPDATE_FLY_INFO_STAUS,new byte[]{data[4]});
                break;
        }
    }

}
